<?php
/**
 * Created by PhpStorm.
 * User: cy
 * Date: 2017/5/31
 * Time: 0:37
 */
header("Content-type:JSON;charset=utf-8");  //统一输出编码为utf-8
header("Access-Control-Allow-Origin:*");//允许跨域

if(!empty($_GET)&&$_GET["pid"]!=""&&$_GET["pid"]!=null){



//创建连接数据
    $conn=new mysqli("127.0.0.1","root","","tiangou");

    //创建连接字符集
    mysqli_query($conn,"set names utf8");

//写入sql语句并执行
    $sql="SELECT*FROM products WHERE prostatus=1 AND pid=".$_GET["pid"];

    $result=$conn->query($sql);
//    print_r($result);
//返回num_rows为1
    $arrinfo=array();
    if($result->num_rows>0){
        //遍历
        while($row=$result->fetch_assoc()){
//            print_r($row) //返回的是每一条数据
            //Array ( [pid] => 4 [plimg] => images/list/i9.jpg [psimg] => images/list/s9.jpg [price] => 锟�12鍏�
            // [description] => LIPO闈㈠寘骞� [prostatus] => 1 [pifkong] => 鐑崠 )

            array_push($arrinfo,$row);
        }
    }
        print_r(json_encode($arrinfo));
}
